package multidraw;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import multidraw.model.DrawingCanvasModel;
import multidraw.model.ModelObserver;
import multidraw.tools.TextBoxTool;
import multidraw.tools.Tool;


/**
 * 
 * @author cuongbk
 * @assoc "attach\ncallServices" - - DrawingCanvasModel
 */
public class DrawingCanvasController implements MouseListener, ModelObserver, MouseMotionListener, KeyListener {
	protected DrawingCanvasModel myModel;
	protected DrawingCanvasView myView;
	
	public DrawingCanvasController(DrawingCanvasModel myModel, DrawingCanvasView myView) {
		this.myModel = myModel;
		this.myView = myView;
	}
	
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		Tool t = myModel.getCurrentTool();
		System.out.println("Mouse Released ...");
		if (t != null) {
			t.mouseReleased(e);
		}
	}

	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Mouse Pressed ...");
		Tool t = myModel.getCurrentTool();
		if (t != null) {
			t.mousePressed(e);
		}
	}

	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		//pick the selected object.
		//canvasMouseClicked(e);
		System.out.println("Mouse Clicked ...");
		Tool t = myModel.getCurrentTool();
		if (t != null) {
			t.mouseClicked(e);
		}
	}
	
	
	
	public void updateContent() {
		//do nothing for now.
	}

	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		System.out.println("Mouse Dragged ...");
		Tool t = myModel.getCurrentTool();
		if (t != null) {
			t.mouseDragged(e);
		}
	}

	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void keyPressed(KeyEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Key pressed ...");
	}

	public void keyReleased(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	public void keyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		System.out.println("Key typed ...");
		//transfer this event to the current tool.
		if (myModel.getCurrentTool() != null) { 
			myModel.getCurrentTool().keyTyped(e);				
		}
	}
}
